package com.example.demo.config;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 多线程注入,线程池
 */
@AutoConfiguration
public class ThreadPoolComfig {
    @Bean//方法注解,把返回值存储到IOC容器中(任务容器)
    public ThreadPoolTaskExecutor taskExecutor(){
        ThreadPoolTaskExecutor executor=new ThreadPoolTaskExecutor();//线程对象
        //设置多线程属性
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(10000);//任务队列(可以有多少个任务)
        executor.setThreadNamePrefix("MyThread-");
        executor.initialize();
        return executor;//把配置好的多线程容器返回即可使用了
    }
}
